package com.swss.util;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 * 读取配置文件信息
 * 
 * @author 
 * 
 */
public class ReadConfig {

	private Configuration mConfiguration = null;

	public ReadConfig() {
		mConfiguration = new Configuration(getProjectPath()
				+ "WEB-INF/classes/webPrintPatch.properties");
	}

	public String getProjectPath() {
		String rootPath = null;
		String path = this.getClass().getClassLoader().getResource("/").getPath();
		try {
			path = URLDecoder.decode(path, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 

		int pos = path.indexOf("WEB-INF");// 判断根目录
		if (pos != -1) {
			rootPath = path.substring(0, pos);
		} else {
			rootPath = path.substring(0, 3);// 无相关文件去盘符下
		}
		
	  	return rootPath.substring(1, rootPath.length());// 除去路径最开头的' /';
		
	}

	/**
	 * 获取配置文件中 指定的ip地址
	 * 
	 * @return
	 */
	public String readPrintIPPath(String keyName) {
		if (mConfiguration != null) {
			return mConfiguration.getValue(keyName);
		}
		return null;
	}

	
}
